//
// Created by Semir on 2020/5/1.
//

#include <iostream>
#include <vector>

using namespace std;

int n, m;
vector<int> lose;
vector<int> win;
vector<int> cost;
vector<long long> dp;

int main() {
    cin >> n >> m;
    lose.resize(n + 1);
    win.resize(n + 1);
    cost.resize(n + 1);
    dp.resize(m + 1);
    for (int i = 1; i <= n; i++) {
        cin >> lose[i] >> win[i] >> cost[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = m; j >= 0; j--) {
            if (j >= cost[i]) {
                dp[j] = max(dp[j] + lose[i], dp[j - cost[i]] + win[i]);
            } else {
                dp[j] += lose[i];
            }

        }
    }
    cout << dp[m] * 5 << endl;
    return 0;
}
